{include file="index/header"}
<body>
<div class="fly-panel fly-panel-user">
    <div class="tpt-admin">
        <div class="tpt-btn">
            <a href="{:url('ShoppingGuideCollect/add')}" class="layui-btn"><i class="layui-icon">&#xe608;</i> 添加采集器</a>
            <button style="margin-bottom: 0px;" class="layui-btn" lay-submit lay-filter="robotquanwang_collect"><i class="layui-icon">&#xe628;</i> 一键采集</button>
        </div>
        <form class="layui-form" method="post">
            <table width="100%">
                <tr>
                    <th width="3%" align="center"><input type="checkbox" name="checkAll" lay-filter="checkAll"></th>
                    <th width="5%" align="center">采集ID</th>
                    <th width="15%" align="center">采集名称</th>
                    <th width="15%" align="center">采集关键词</th>
                    <th width="10%" align="center">采集入库分类</th>
                    <th width="5%" align="center">采集页数</th>
                    <th width="6%" align="center">今日采集状态</th>
                    <th width="6%" align="center">上次采集时间</th>
                    <th width="15%" align="center">基本操作</th>
                </tr>
                {volist name="shoppingGuideList" id="vo"}
                <tr>
                    <td align="center"><input type="checkbox" name="ids[{$vo.id}]" lay-filter="checkOne" value="{$vo.id}"></td>
                    <td align="center">{$vo.id}</td>
                    <td align="center">{$vo.name}</td>
                    <td align="center">{$vo.keyword}</td>
                    <td align="center">{$vo.categoryName}</td>
                    <td align="center">{$vo.page_no}</td>
                    <td align="center">{if condition="$vo.lastTime eq ''"}未采集{else /}{if condition="(date('Y-m-d',$Today) neq date('Y-m-d',$vo.lastTime))"}未采集{elseif condition="(date('Y-m-d',$Today) eq date('Y-m-d',$vo.lastTime)) AND ($vo.lastPage eq '0')" /}已集采{else /}已集采{$vo.lastPage}页{/if}{/if}</td>
                    <td align="center">{if condition="$vo.lastTime eq ''"}未采集{else /}{$vo.lastTime|date="Y-m-d",###}{/if}</td>
                    <td align="center">
                        <a class="layui-btn layui-btn-mini" id="collect_one" member-id="{$vo.id}" title="采集" ><i class="layui-icon">&#xe628;</i> 采集</a>
                        <a class="layui-btn layui-btn-mini layui-btn-warm" href="{:url('ShoppingGuideCollect/edit',array('id'=>$vo['id']))}">修改</a>
                        <a class="layui-btn layui-btn-mini layui-btn-danger del_btn" member-id="{$vo.id}" title="删除" nickname="{$vo.name}">删除</a>
                    </td>
                </tr>
                {/volist}
            </table>
            <!-- 分页导航 -->
            {if condition="$shoppingGuideList->render() neq ''"}
            <div style="text-align: center">
                <div class="laypage-main">
                    {$shoppingGuideList->render()}
                </div>
            </div>
            {/if}
            <div class="layui-form-item">
                <div style="margin-top: 20px;float: left;">
                    <button class="layui-btn" lay-submit lay-filter="delete">删除选中</button>
                </div>
            </div>
        </form>
    </div>
</div>
{include file="index_footer"}
<script type="text/javascript">
    layui.use('form',function(){
        var form = layui.form()
            ,jq = layui.jquery;

        // 单个删除
        jq('.del_btn').click(function(){
            var name = jq(this).attr('nickname');
            var id = jq(this).attr('member-id');
            layer.confirm('确定删除【'+name+'】?', function(index){
                loading = layer.load(2, {
                    shade: [0.2,'#000']
                });
                jq.post('{:url("ShoppingGuideCollect/dels")}',{'id':id},function(data){
                    if(data.code == 200){
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                            location.reload();
                        });
                    }else{
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
                    }
                });
            });
        });

        form.on('checkbox(checkAll)', function(data){
            if(data.elem.checked){
                jq("input[type='checkbox']").prop('checked',true);
            }else{
                jq("input[type='checkbox']").prop('checked',false);
            }
            form.render('checkbox');
        });

        form.on('checkbox(checkOne)', function(data){
            var is_check = true;
            if(data.elem.checked){
                jq("input[lay-filter='checkOne']").each(function(){
                    if(!jq(this).prop('checked')){ is_check = false; }
                });
                if(is_check){
                    jq("input[lay-filter='checkAll']").prop('checked',true);
                }
            }else{
                jq("input[lay-filter='checkAll']").prop('checked',false);
            }
            form.render('checkbox');
        });

        // 批量删除
        form.on('submit(delete)', function(data){
            var is_check = false;
            jq("input[lay-filter='checkOne']").each(function(){
                if(jq(this).prop('checked')){ is_check = true; }
            });
            if(!is_check){
                layer.msg('请选择数据', {icon: 2,anim: 6,time: 1000});
                return false;
            }
            layer.confirm('确定批量删除?', function(index){
                loading = layer.load(2, {
                    shade: [0.2,'#000']
                });
                var param = data.field;
                jq.post('{:url("ShoppingGuideCollect/delss")}',param,function(data){
                    if(data.code == 200){
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                            location.reload();
                        });
                    }else{
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 2,anim: 6, time: 1000});
                    }
                });
            });
            return false;
        });

        // 批量采集
        var collect_layer_index = null;
        form.on('submit(robotquanwang_collect)', function(data){
            layer.confirm('确定开始采集?', function(index){
                collect_layer_index = layer.open({
                    type:0,
                    content:'开始采集,正在准备数据，请稍候！',
                    btn: false,
                    area: ['300px', '150px'],
                    cancel:function(index,layero){
                        layer.close(index);
                        location.reload();
                    }
                });
                collect_get_all({});
            });
            return false;
        });
        function collect_get_all(param){
            jq.ajax({
                url:'{:url("ShoppingGuideCollect/collect_all")}',
                data:param,
                type:'post',
                success:function(data){
                    $('.layui-layer-content').text(data.msg);
                    // if(data.code == 200){
                    //     collect_get_all({id:data.id,num:data.num});
                    // }
                },
                dataType:'json'
            });
        }

        // 单个采集
        var collect_layer_index_one = null;
        $('#collect_one').click(function(){
            var id = jq(this).attr('member-id');
            collect_layer_index_one = layer.open({
                type:0,
                content:'开始采集,正在准备数据，请稍候！',
                btn: false,
                area: ['300px', '150px'],
                cancel:function(index,layero){
                    layer.close(index);
                    location.reload();
                }
            });
            collect_get_one({id:id});
        });
        function collect_get_one(param){
            jq.ajax({
                url:'{:url("ShoppingGuideCollect/collect_one")}',
                data:param,
                type:'post',
                success:function(data){
                    if(data.code == 200){
                        $('.layui-layer-content').text(data.msg);
                    }else{
                        // if(data.code == 200){
                            $('.layui-layer-content').text(data.msg);
                            // param.num = data.num;
                            // collect_get_one(param);
                        // }
                    }
                },
                dataType:'json'
            });
        }
    })
</script>
</body>
</html>


